<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <div id="app">
        <ul>
            <li>西游记；价格：{{xyjPrice}}，数量：<input type="number" v-model="xyjNum" /> </li>
            <li>水浒传；价格：{{shzPrice}}，数量：<input type="number" v-model="shzNum" /> </li>
            <li>金瓶梅；价格：{{jpmPrice}}，数量：<input type="number" v-model="jpmNum" /> </li>
            <li>总价：{{totalPrice}}</li>
        </ul>
    </div>

    <script>
        new Vue({
            el: "#app",
            data: {
                xyjPrice: 59.9,
                shzPrice: 69.9,
                jpmPrice: 99.9,
                xyjNum: 1,
                shzNum: 1,
                jpmNum: 1
            },
            computed: {
                totalPrice() {
                    return this.xyjNum * this.xyjPrice + this.shzNum * this.shzPrice + this.jpmNum * this.jpmPrice
                }
            },
            watch: {
                xyjNum: function (newValue) {
                    if(newValue < 0){
                        this.xyjNum = 0;
                    }
                }
            }

        })
    </script>
</body>

</html>